package edu.umd.ion.wavemeter.service;


/**
 * Exception class for Set-Function failures 
 * @author monroe-lab
 *
 */
public class WavemeterSetException extends WavemeterException {
	static final long serialVersionUID = 1;
	public static final String[] Message = {"No Error","wavemeter missing","could not set","parameter out of range",
		"wavemeter out of resources","wavemeter internal error","not available","wavemeter busy",
		"wavemeter not in measurement mode","only in measurement mode","channel not available",
		"channel temporarily not available", "calibration option not available", "calibration wavelength out of range",
		"bad calibratioin signal", "unit not available" };
	
	public WavemeterSetException() {
		super();
	}
	
	public WavemeterSetException(String message) {
		super(message);
	}

	/**
	 * Generate Exception with error mesage built from the name of the
	 * calling funtion and the errorcode returned by the WavemeterLibrary
	 * Set-Function.
	 * @param function
	 * @param errorcode
	 */
	public WavemeterSetException(String setfunction, int errorcode) {
		super(formatMessage(setfunction,errorcode));
	}
	
	protected static String formatMessage(String setfunction, int errorcode)
	{
		if ( errorcode>0 || errorcode<-15 )
			return "Wavemeter set-function '"+setfunction+"' errorcode out of range";
		else
			return "Wavemeter set-function '"+setfunction+"' reported error '"+Message[-errorcode]+"'";		
	}
}
